/* Formulario para visualizar las acciones de
 * los jugadores
 * + Crear Unidad
 * + Atacar
 */
function PlayerDetails(_playerView, _map){
	
	var AnnotationType = require('ui/model/constants/AnnotationType');
	
	//Jugador
	var playerView = _playerView;
	var map = _map;
	
	var self = Ti.UI.createView({
		backgroundColor:'lightgray',
		right:'0%',
		width:'30%'
	});
	
	var title = Ti.UI.createLabel({
		text:'Player: ' + Ti.App.controller.player.name,
		top:'0px',
		color: '#900',
  		font: { fontSize:14, fontWeight:'bold', textStyle:Titanium.UI.TEXT_STYLE_HEADLINE },
  		//shadowColor: '#aaa',
  		//shadowOffset: {x:5, y:5},
  		shadowRadius: 3,
  		textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER,
  		width: Ti.UI.SIZE, height: Ti.UI.SIZE
	});
	
	var btnCreateTroop = Ti.UI.createButton({
		title:'Crear Tropa',
		top: '50px',
		font: { fontSize:14 }
	});
	
	var btnCreateMotorcycle = Ti.UI.createButton({
		title:'Crear Moto',
		top: '130px',
		font: { fontSize:14 }
	});
	
	
	var btnCreateTank = Ti.UI.createButton({
		title:'Crear Tanque',
		top: '210px',
		font: { fontSize:14 }
	});
	
		
	var btnUseCard = Ti.UI.createButton({
		title:'Usar Tarjeta',
		top: '290px',
		font: { fontSize:14 }
	});
	
	
	var lblTroops = Ti.UI.createLabel({
		text: 'Tropas Creadas: ' + Ti.App.controller.getCountTroops(),
		top:'360px',
		color: '#900',
		font: { fontSize:14, fontWeight:'bold', textStyle:Titanium.UI.TEXT_STYLE_HEADLINE },
  		shadowRadius: 3,
  		textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER,
  		width: Ti.UI.SIZE, height: Ti.UI.SIZE
	});
	
	var lblTroopsBuilding = Ti.UI.createLabel({
		text: 'Tropas Construyendose: ' + Ti.App.controller.player.getCountTroopsBuilding(),
		top:'380px',
		color: '#900',
		font: { fontSize:14, fontWeight:'bold', textStyle:Titanium.UI.TEXT_STYLE_HEADLINE },
  		shadowRadius: 3,
  		textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER,
  		width: Ti.UI.SIZE, height: Ti.UI.SIZE
	});
	
	var lblActionPoints = Ti.UI.createLabel({
		text: 'Puntos de Accion: ' + Ti.App.controller.player.actionPoints,
		top:'400px',
		color: '#900',
		font: { fontSize:14, fontWeight:'bold', textStyle:Titanium.UI.TEXT_STYLE_HEADLINE },
  		shadowRadius: 3,
  		textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER,
  		width: Ti.UI.SIZE, height: Ti.UI.SIZE
	});
	
	var lblMonetaryPoints = Ti.UI.createLabel({
		text: 'Puntos Monetarios: ' + Ti.App.controller.player.monetaryPoints,
		top:'420px',
		color: '#900',
		font: { fontSize:14, fontWeight:'bold', textStyle:Titanium.UI.TEXT_STYLE_HEADLINE },
  		shadowRadius: 3,
  		textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER,
  		width: Ti.UI.SIZE, height: Ti.UI.SIZE
	});
	
	var refreshView = function(){
		lblTroopsBuilding.text = 'Tropas Construyendose: ' + Ti.App.controller.player.getCountTroopsBuilding();	
		lblTroops.text = 'Tropas Creadas: ' + Ti.App.controller.getCountTroops();
		lblActionPoints.text =  'Puntos de Accion: ' + Ti.App.controller.player.actionPoints;
		lblMonetaryPoints.text = 'Puntos Monetarios: ' + Ti.App.controller.player.monetaryPoints;
	};
	
	btnCreateTroop.addEventListener('click',function(){
		_playerView.createTroop(AnnotationType.ANNOTATION_TROOP);
		refreshView();			
	});
	
	btnCreateMotorcycle.addEventListener('click',function(){
		_playerView.createTroop(AnnotationType.ANNOTATION_MOTORCYCLE);
		refreshView();			
	});
	
	btnCreateTank.addEventListener('click',function(){
		_playerView.createTroop(AnnotationType.ANNOTATION_TANK);
		refreshView();			
	});
	
		
	self.add(title);
	self.add(btnCreateTroop);
	self.add(btnCreateMotorcycle);
	self.add(btnCreateTank);
	self.add(btnUseCard);
	self.add(lblTroops);
	self.add(lblTroopsBuilding);
	self.add(lblActionPoints);
	self.add(lblMonetaryPoints);
	
	return self;
	
}

module.exports = PlayerDetails;
